use strict;
use warnings;
use Data::Dumper;
use Bio::Rambam::Proteomics::Engines;
use Bio::Rambam::Proteomics::Search;
use Bio::Rambam::Proteomics::MzML;
#use Bio::Rambam::Proteomics::Formats::FastaDatabase;
#use Cwd;
#my $location= Cwd::abs_path(__FILE__);
#$location=~s/test_search\.pl$//;


my $output_folder="/home/david/Desktop/tfm_fat";
my $engines=Bio::Rambam::Proteomics::Engines->new(
													omssa=>'/home/david/software/omssa-2.1.9.linux/omssacl',
													comet=>'/home/david/software/comet/comet.2013010.linux.exe',
													xtandem=>'/home/david/software/tandem-linux-13-02-01-1/bin/tandem.exe',
													myrimatch =>'/home/david/software/myrimatch/myrimatch',	
												);
												
#####	test
#my $fasta_location	="/home/david/Desktop/busquedas/fastas/testDB.fasta";
#my $input_file="/home/david/Desktop/busquedas/spectra/test.mzML";
#my $mzml=Bio::Rambam::Proteomics::MzML->new(file=>$input_file);
#my $mgf=$mzml->create_mgf();
#busca($mgf);
#########

#####	real
my $fasta_location	="/home/david/databases/uniprot2014_07_human.reversed.fasta";
while(</home/david/Desktop/tfm_fat/spectra/*.mzML>){
	my $input_file=$_;
	my $mzml=Bio::Rambam::Proteomics::MzML->new(file=>$input_file);
	my $mgf=$mzml->create_mgf();
	busca($mgf);
}


#########



#my $db=Bio::Rambam::Proteomics::Formats::FastaDatabase->new(file=>$fasta_location);
#$db->reversedb();



### al comet la pasa lo mismo que a la generacion de la fasta reversa: al escribir el ms2, se come el primer caracter. Aunque no peta, miratelo.



sub busca{
	my $mgf=shift;
	my $search=Bio::Rambam::Proteomics::Search->new(
												folder	 		=> $output_folder,
												input_file		=> $mgf->file,
												engines	 		=> $engines,
												database 		=> $fasta_location,
												enzyme	 		=> "Trypsin",
												fixed_mods		=>'4@C,214@Nt',
												variable_mods	=>'35@M,214@Y',
												miss_cleavages	=>2,
												fragmentation	=>'CID',
												threads=>8,
												);
	my $results=$search->exec();
	open OUT,">>","/home/david/Desktop/tfm_fat/files.txt";
	#print OUT "OMSSA\t",$search->input_file(),"\t",${$search->outputs}{omssa},"\n";
	#print OUT "COMET\t",$search->input_file(),"\t",${$search->outputs}{comet},"\n";
	#print OUT "XTANDEM\t",$search->input_file(),"\t",${$search->outputs}{xtandem},"\n";
	print OUT "MYRIMATCH\t",$search->input_file(),"\t",${$search->outputs}{myrimatch},"\n";
	close OUT;
	print "#######\tFin busqueda de:\t". $mgf->file."\n";
}




